<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .modal{
        
        position: absolute;        
        left:50%;
        top:50%;
        transform: translate(-50%,-50%);
        width: 400px;
        height: 400px;
        background-color: #ededed;
    }
</style>

<body>
    <div id="app">
        <p>{{msg}}</p>
        <hr/>
        <modal-button></modal-button>
    </div>
    <hr />
</body>

</html>
<script src="./js/vue.global.js"></script>
<script>


    // 1、创建一个应用
    let app = Vue.createApp({
        data() {
            return {
                msg: "hi"
            }
        }
    });

    app.component('modal-button', {
        template: `
			<div style="position: relative;">
                <button @click="modalOpen = true">
                    打开全屏的模态窗口
                </button>      
                <teleport to="body">
					<!--以下html代码的父元素是body标签-->
                    <div v-show="modalOpen" class="modal">
                        <div>
                            I'm a modal! 
                            <button @click="modalOpen = false">
                            Close
                            </button>
                        </div>
                  </div>
                </teleport>
			</div>
            `,
        data() {
            return {
                modalOpen: false
            }
        }
    })


    // 2、把应用进行渲染（和模板进行关联）
    app.mount("#app");


</script>